package com.achen.controller;

import com.achen.entity.Dept;
import com.achen.entity.Result;
import com.achen.service.DeptService;
import com.achen.util.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author achen
 * @create 2020-04-30 22:53
 */
@RestController
@RequestMapping("/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @RequestMapping("/findByPage")
    public Result findByPage(Integer page, Integer limit) {
        try {
            List<Dept> list = deptService.findByPage(page, limit);
            Integer count = deptService.findCount();
            return new Result(0, Constant.SEARCH_SUCCESS, count, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(1,Constant.SEARCH_FAIL);
        }
    }

    @RequestMapping("/findBySearch")
    public Map findBySearch(Integer page,Integer limit,String keyword){
        System.out.println(keyword);
        Map map  = deptService.findBySearch(keyword, page, limit);
        System.out.println(map);
        return map;
    }
}
